<?php

header ('Content-type: text/html; charset=UTF-8'); 


?>


<script src="system.js"></script>


<script language="javascript" type="text/javascript">





function returnListviewData(jsonObj){
	
	
	
	if( jsonObj.status == 1){
		

		var grid_view_html="";
		

		var obj_json = JSON.parse(jsonObj.data);

		var i;
		//alert(obj_json.length);
		var columns="";
		
		
		for (i=0; i < obj_json.length; i++){
		    //var img = new Image();
		    //img.setAttribute("src",obj[i][2] + obj[i][1]);
		    //document.body.appendChild(img);
		    //alert( obj_json[i].name_view );
		    
		    //alert("name="+obj_json[i].name );
		    
		    if( columns==''){
		    	columns = columns +"<tr>";

		    	for (var key in obj_json[i]) {
			    	
					columns = columns +"<td>"+key+"</td>";
			    	
				}
				columns = columns +"</tr>";
		    }
		    
			

		    grid_view_html = grid_view_html +"<tr>";
			
		    for (var key in obj_json[i]) {
			    	
				grid_view_html = grid_view_html +"<td>"+obj_json[i][key]+"</td>";
			    	
			}

		    grid_view_html = grid_view_html +"</tr>";
		    	
		    
		    // grid_view_html = grid_view_html +"<tr>"
// 		    		
		    			// +"<td>"+obj_json[i].id+"</td>"
		    			// +"<td>"+obj_json[i].name_view+"</td>"
		    			// +"<td>"+obj_json[i].table_name+"</td>"
		    			// +"<td>"+obj_json[i].db_hostip+"</td>"
		    			// +"<td>"+obj_json[i].detail+"</td>"
		    			// +"<td>"+obj_json[i].date_create+"</td>"
		    			// +"</tr>";
		    
		}


		document.getElementById("grid_view").innerHTML = "<table border=1>"+columns+grid_view_html+"</table>";
		//document.getElementById("grid_view").innerHTML = "<table border=1><tr><td>#</td><td>id</td><td>nome</td><td>table</td><td>host</td><td>detalhe</td><td>criado</td></tr>"+grid_view_html+"</table>";

		
		
	}else{
		
		alert(jsonObj.data);
		
		if(jsonObj.notification==25){
			window.location.href='index.php';
		}
	}


	
}


function getQueryExecute( query ) 
{
	
	var oObject = {} ;
					
	oObject["id"] = 0;
	oObject["limit"] = 10;
	oObject["offset"] = 0;
	oObject["column"] = "id";
	oObject["order"] = "asc";
	oObject["query"] = encodeURIComponent(query);
	oObject["component"] = "filter";
	oObject["controller"] = "query";
	oObject["task"] = "query";
	
	
	var jsonVales	=	convertToJSON(oObject);
	
	parameters	=	'parameters='+encodeURIComponent(
							convertToStringJSON(jsonVales));
	
	var method='GET';
		
	httpRequest ( method,
					url_API,
					parameters,
					'returnListviewData');
}




</script>


<h1>Lista de Visões</h1>

<div id="text-result-view" style="visibility:hidden;width:1px;height:1px;"></div>
<div id="text-result-hidden" style="visibility:hidden;width:1px;height:1px;"></div>
<div id="text-result-hidden-username" style="visibility:hidden;width:1px;height:1px;"></div>

<div id="text-result">Area restria aos usuarios autenticados. voce esta logado como <div id="username-id"></div>.<a href="#" onclick="javascript:logout();">Clique aqui para Logout</a></div>
 
<br>


<a href="home_authenticated.php">Página inicial</a><br>

<a href="view_edit.php">Nova Visão</a><br>


<form class="cmxform" action="" method="GET">	
	<input type="hidden" name="id" id="id" value=''>
	
	<div id="label">query</div> <div id="field">
		<textarea id="query" name="query" style="width:500px;height:150px;"  ></textarea>		
	</div>
	
	
	<input type="button" name="executar" value="executar" onclick="javascript:getQueryExecute(document.getElementById('query').value );"/>

	<input type="button" name="cancelar" value="Cancelar" onclick="javascript:window.location.href='view_list.php';"/>
	
</form>


<div id="grid_view"></div>




    
<script>
getUsername();
//getListView(10,0,"id","desc");

</script>